<?php

/**
 * This is the model class for table "comment".
 *
 * The followings are the available columns in table 'comment':
 * @property string $idcomment
 * @property string $content_comment
 * @property string $created_comment
 * @property string $status_comment
 * @property string $author_comment
 * @property string $email
 * @property string $url
 * @property string $user_id
 * @property string $post_idpost
 *
 * The followings are the available model relations:
 * @property User $user
 * @property Post $postIdpost
 */
class Comment extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'comment';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('content_comment, author_comment, email, user_id, post_idpost', 'required'),
			array('status_comment', 'length', 'max'=>1),
			array('author_comment', 'length', 'max'=>255),
			array('email, url', 'length', 'max'=>128),
			array('user_id, post_idpost', 'length', 'max'=>50),
			array('created_comment', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('idcomment, content_comment, created_comment, status_comment, author_comment, email, url, user_id, post_idpost', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'user' => array(self::BELONGS_TO, 'User', 'user_id'),
			'postIdpost' => array(self::BELONGS_TO, 'Post', 'post_idpost'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idcomment' => 'Idcomment',
			'content_comment' => 'Content Comment',
			'created_comment' => 'Created Comment',
			'status_comment' => 'Status Comment',
			'author_comment' => 'Author Comment',
			'email' => 'Email',
			'url' => 'Url',
			'user_id' => 'User',
			'post_idpost' => 'Post Idpost',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idcomment',$this->idcomment,true);
		$criteria->compare('content_comment',$this->content_comment,true);
		$criteria->compare('created_comment',$this->created_comment,true);
		$criteria->compare('status_comment',$this->status_comment,true);
		$criteria->compare('author_comment',$this->author_comment,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('url',$this->url,true);
		$criteria->compare('user_id',$this->user_id,true);
		$criteria->compare('post_idpost',$this->post_idpost,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Comment the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
